package com.seocoo.worker.user.account;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.seocoo.worker.R;
import com.seocoo.worker.base.ImageLoaderEngine;
import com.seocoo.worker.base.UtilStatus;
import com.seocoo.worker.base.http.BasePageRsp;
import com.seocoo.worker.base.widget.AppToolBer;
import com.seocoo.worker.user.account.entity.EDepositDesc;
import com.sfh.lib.mvvm.LiveDataMatch;
import com.sfh.lib.ui.MVVMActivity;

/***
 * 提现详情
 */
public class DepositDescActivity extends MVVMActivity {

    public static void start(Context context, EDepositDesc desc) {
        Intent intent = new Intent(context, DepositDescActivity.class);
        intent.putExtra("data", new Gson().toJson(desc));
        context.startActivity(intent);
    }

    private AppToolBer appToolBer;
    private ImageView ivStatus;
    private TextView tvStatus;
    private TextView tvDate;
    private TextView tvMoney;
    private TextView tvBank;
    private TextView tvOk;
    private TextView tvRemark;
    private ImageView ivOkPic;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_deposit_desc_activity);
        UtilStatus.initStatus(this, Color.WHITE);
        initView();
    }


    private void initView() {
        appToolBer = (AppToolBer) findViewById(R.id.appToolBer);
        ivStatus = (ImageView) findViewById(R.id.iv_status);
        tvStatus = (TextView) findViewById(R.id.tv_status);
        tvDate = (TextView) findViewById(R.id.tv_date);
        tvMoney = (TextView) findViewById(R.id.tv_money);
        tvBank = (TextView) findViewById(R.id.tv_bank);
        tvOk = (TextView) findViewById(R.id.tv_ok);
        tvRemark = (TextView) findViewById(R.id.tv_remark);
        ivOkPic = (ImageView) findViewById(R.id.iv_ok_pic);

        EDepositDesc desc = new Gson().fromJson(getIntent().getStringExtra("data"), EDepositDesc.class);

        tvBank.setText(desc.bankName + "(" + desc.cardNo.substring(desc.cardNo.length() - 4) + ")");
        tvMoney.setText(desc.money + "元");
        tvDate.setText(desc.createdTime);

        //2-提现成功 3-提现失败
        if (desc.depositState == 2) {
            tvStatus.setText("提现成功");
            ivStatus.setImageResource(R.drawable.user_account_desc_ok);
            tvOk.setText("转账凭证");
            tvRemark.setVisibility(View.GONE);
            ivOkPic.setVisibility(View.VISIBLE);
            if (TextUtils.isEmpty(desc.picUrl)) {
                ivOkPic.setVisibility(View.GONE);
            } else {
                ivOkPic.setVisibility(View.VISIBLE);
                new ImageLoaderEngine(desc.picUrl).error(R.drawable.order_detail_top_green_commission).placeholder(R.drawable.order_detail_top_green_commission).into(ivOkPic);
            }
        } else if (desc.depositState == 3) {
            tvStatus.setText("提现失败");
            ivStatus.setImageResource(R.drawable.user_account_desc_fail);
            tvOk.setText("提现失败原因");
            tvRemark.setVisibility(View.VISIBLE);
            tvRemark.setText(desc.remark);
            ivOkPic.setVisibility(View.GONE);
        }
    }
}
